package com.pxmeta.product.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pxmeta.product.entity.Shop;
import com.pxmeta.product.entity.UserShop;
import com.pxmeta.product.mapper.ShopMapper;
import com.pxmeta.product.mapper.UserShopMapper;
import com.pxmeta.product.service.IShopService;
import com.pxmeta.product.service.IUserShopService;
import com.pxmeta.user.service.IUserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@Slf4j
@RequiredArgsConstructor
public class UserShopServiceImpl extends ServiceImpl<UserShopMapper, UserShop> implements IUserShopService {
    @Override
    public void add(Long userId, Shop shop, Integer days) {
        UserShop userShop = new UserShop();
        userShop.setShopId(shop.getId());
        userShop.setUserId(userId);
        userShop.setShopType(shop.getCategory());
        userShop.setIsUse(Boolean.FALSE);
        LocalDateTime endTime = LocalDateTime.now().plusDays(days);
        userShop.setEndTime(endTime);
        this.save(userShop);
    }
}
